package com.example.demo.utils;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    //在这个方法里定义我们需要返回的格式
    public Result handleUserNotExistException(CustomException ex){
        //获取到我们定义的msg
        //result.put("message", ex.getMessage());
        return Result.failure(Integer.parseInt(ex.getCode()),ex.getMsg());
    }
}
